<?php
declare(strict_types=1);

namespace App\Controller\admin;

use App\Controller\AbstractController;
use App\Request\Admin\LoginRequest;
use App\Service\Admin\UserService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;

#[Controller(prefix: '/api/admin/auth')]
class AuthController extends AbstractController
{
    #[Inject]
    private UserService $userService;

    #[PostMapping('login')]
    public function login(LoginRequest $request)
    {
        $data = $request->validated();

        $token = $this->userService->login($data);

        return [
            'token' => $token,
            'exp' => time() + config('jwt.ttl')
        ];
    }
}